<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>处理数据回滚</title>
    <script src="script/vue.js"></script>
    <script src="script/axios.js"></script>
    <script src="comment/main.js"></script>
</head>
<body>
<div id="app">

</div>
<script type="text/javascript">
    new Vue({
        el: "#app",
        data: {
            wxLoginPram: null
        },
        methods: {
            wxLogin() {
                this.$http.post("/login/wechat",this.wxLoginPram)
                    .then(res => {
                        res = res.data;
                        if (res.success) {
                            if (res.data.token) {
                                // 1.免密登录
                                localStorage.setItem('token', res.data.token);
                                localStorage.setItem('loginUser', JSON.stringify(res.data.loginUser));
                                location.href = "/index.html";
                            } else {
                                // 2.绑定手机号
                                var accessToken = res.data.access_token;
                                var openId = res.data.openid;
                                location.href = `/binder.html?access_token=${accessToken}&openid=${openId}`
                            }
                        } else {
                            alert(res.msg)
                        }
                    })
                    .catch(err => {
                        alert("网络异常");
                    })
            }
        },
        mounted() {
            this.wxLoginPram = parseUrl();
            this.wxLogin();
        }
    })
</script>
</body>
</html>